From 2f6dc1bf8cf81192ef270ef0654704f8b12173ee Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 8 Dec 2014 12:34:31 -0800 Subject: [PATCH] Fix build scripts in dev-dependencies Don't return dev-dependencies as dependencies for non-test targets as they're not actually dependencies! --- src/cargo/ops/cargo_rustc/context.rs | 17 ++++++++++++---- tests/test_cargo_compile_custom_build.rs | 25 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index a743e4f91..def445d89 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -272,13 +272,22 @@ impl<'a, 'b: 'a> Context<'a, 'b> { Some(deps) => deps, }; deps.map(|id| self.get_package(id)).filter(|dep| { - // If this target is a build command, then we only want build - // dependencies, otherwise we want everything *other than* build - // dependencies. let pkg_dep = pkg.get_dependencies().iter().find(|d| { d.get_name() == dep.get_name() }).unwrap(); - target.get_profile().is_custom_build() == pkg_dep.is_build() + + // If this target is a build command, then we only want build + // dependencies, otherwise we want everything *other than* build + // dependencies. + let is_correct_dep = + target.get_profile().is_custom_build() == pkg_dep.is_build(); + + // If this dependency is *not* a transitive dependency, then it + // only applies to test targets + let is_actual_dep = pkg_dep.is_transitive() || + target.get_profile().is_test(); + + is_correct_dep && is_actual_dep }).filter_map(|pkg| { pkg.get_targets().iter().find(|&t| self.is_relevant_target(t)) .map(|t| (pkg, t)) diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index aef3c77e0..eb3d8eef3 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -975,3 +975,28 @@ test!(test_a_lib_with_a_build_command { assert_that(p.cargo_process("test"), execs().with_status(0)); }) + +test!(test_dev_dep_build_script { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dev-dependencies.a] + path = "a" + "#) + .file("src/lib.rs", "") + .file("a/Cargo.toml", r#" + [project] + name = "a" + version = "0.5.0" + authors = [] + build = "build.rs" + "#) + .file("a/build.rs", "fn main() {}") + .file("a/src/lib.rs", ""); + + assert_that(p.cargo_process("test"), execs().with_status(0)); +}) -- 2.30.2